package com.zc.edu.controller.front;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.zc.edu.entity.Course;
import com.zc.edu.entity.Teacher;
import com.zc.edu.service.CourseService;
import com.zc.edu.service.TeacherService;
import com.zc.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/eduService/frontIndex")
@CrossOrigin
public class FrontIndexController {
	@Autowired
	private TeacherService teacherService;

	@Autowired
	private CourseService courseService;

	// 查询前八条热门课程，前四条讲师
	@GetMapping("/index")
	public R index() {
		QueryWrapper<Course> courseQueryWrapper = new QueryWrapper<>();
		courseQueryWrapper.orderByDesc("id").last("limit 8");
		List<Course> courseList = courseService.list(courseQueryWrapper);

		QueryWrapper<Teacher> teacherQueryWrapper = new QueryWrapper<>();
		teacherQueryWrapper.orderByDesc("id").last("limit 4");
		List<Teacher> teacherList = teacherService.list(teacherQueryWrapper);
		return R.ok().data("courseList", courseList).data("teacherList", teacherList);
	}

}
